<template>
    <div class="cont mb-4">
        <CustomQuery @submit="changeQuery" :form-columns="queryList"></CustomQuery>
    </div>
    <div class="cont">
        <CustomTable selection :columns="columns" :data-source="data">
            <template #table-left-nav>
                <a-button @click="useGo" type="primary" :icon="h(PlusOutlined)">添加运营城市</a-button>
            </template>
            <template #column-head="{ record }">
                <img class="w-18 h-18 rounded-full" :src="record.head" alt="用户头像">
            </template>
            <template #column-state="{ column }">
                <a-tag color="green">活跃</a-tag>
            </template>
            <template #column-action="{ record }">
                <a-switch v-model:checked="record.checked" />
            </template>
        </CustomTable>
    </div>
</template>

<script setup lang="ts">
import { PlusOutlined } from '@ant-design/icons-vue';
import { h } from 'vue'

import CustomTable from '@/components/customTable/CustomTable.vue';
import CustomQuery from '@/components/customQuery/CustomQuery.vue';
import { CustomQueryColumns, CustomQueryValue } from '@/components/customQuery/types';
import { CustomTableColumns, CUstomTableData } from '@/components/customTable/types';

const router = useRouter()
const useGo = () => {
    router.push('/cityManagement/city/add')
}

const queryList = reactive<CustomQueryColumns[]>([
    { label: '城市编号', key: 'code', type: 'input' },
    {
        label: '地区', key: 'location', type: 'cascader', options: [
            {
                value: 'zhejiang',
                label: 'Zhejiang',
                children: [
                    {
                        value: 'hangzhou',
                        label: 'Hangzhou',
                        children: [
                            {
                                value: 'xihu',
                                label: 'West Lake',
                            },
                        ],
                    },
                ],
            },
            {
                value: 'jiangsu',
                label: 'Jiangsu',
                children: [
                    {
                        value: 'nanjing',
                        label: 'Nanjing',
                        children: [
                            {
                                value: 'zhonghuamen',
                                label: 'Zhong Hua Men',
                            },
                        ],
                    },
                ],
            },
        ]
    },
    { label: '城市名称', key: 'cityName', type: 'input' },
    {
        label: '状态', key: 'state', type: 'select', options: [
            { label: '状态: 全部', value: '1' },
            { label: '状态: 启用', value: '2' },
            { label: '状态: 禁用', value: '3' },
        ],value:'1'
    }
])

const changeQuery = (queryState: CustomQueryValue) => {
    alert('查询结果为' + JSON.stringify(queryState))
}

const data = ref<CUstomTableData[]>([])
const columns = reactive<CustomTableColumns[]>([
    {
        title: "编号",
        dataIndex: "code",
        key: "code",
    },
    {
        title: "城市",
        dataIndex: "city",
        key: "city",
    },
    {
        title: "起步价",
        dataIndex: "startingPrice",
        key: "startingPrice",
    },
    {
        title: "平台抽成",
        dataIndex: "platformCommission1",
        key: "platformCommission",
    },
    {
        title: "代理抽成",
        dataIndex: "platformCommission2",
        key: "platformCommission",
    },
    {
        title: "代理人",
        dataIndex: "agent",
        key: "agent",
    },
    {
        title: "状态",
        dataIndex: "state",
        key: "state",
        bodyCell: 'state'
    },
    {
        title: "时间",
        dataIndex: "time",
        key: "time",
    },
    {
        flag: 'ACTION'
    },
]);


onMounted(() => {
    for (let i = 0; i < 100; i++) {
        data.value.push(
            { code: '01', city: '沈阳市', startingPrice: '6', platformCommission1: '50%,', platformCommission2: '10%', state: '1', time: '2024-08-16', checked: true },
        )
    }
})
</script>

<style scoped></style>